//
//  UcfgroupXMPPManger.h
//  WXIM
//
//  Created by fusuwei on 14-6-12.
//  Copyright (c) 2014年 fusuwei. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>
#import "XMPPFramework.h"

#import "XMPPAutoPing.h"

#import "ChatGroupMgr.h"
#import "ChatLoginUser.h"
#import "MessageBase.h"
#import "EWxChatMgrLoginDelegate.h"
#import "EWxChatMgrChatDelegate.h"
#import "EWxChatMgrContactDelegate.h"
#import "EWxChatMgrGroupDelegate.h"
#import "XMPPHTTPFileUpload.h"

@class XMPPMessage,XMPPRoster,XMPPRosterCoreDataStorage;

//block define
typedef void (^completionBlock)(NSDictionary *loginInfo, EWxLoginRegState state);

typedef void (^contactGroupsCompletionBlock)(BOOL state);



@interface UcfgroupXMPPManger : NSObject <XMPPAutoPingDelegate>


@property (strong, nonatomic) XMPPStream *xmppStream;
@property (strong, nonatomic) XMPPAutoPing *xmppAutoPing;

@property (strong, nonatomic) XMPPHTTPFileUpload *xmppUpload;//文件上传的类

@property (strong, nonatomic) ChatLoginUser *logRegWxUserObject; //当前注册或登录的用户


@property (assign, nonatomic) BOOL isReg;

@property (strong, nonatomic) NSString *deviceToken;

@property (nonatomic, weak) id <EWxChatMgrContactDelegate> xmppContactDelegate; //联系人模块
@property (nonatomic, weak) id <EWxChatMgrChatDelegate> xmppMsgDelegate; //收发消息 代理
@property (nonatomic, weak) id <EWxChatMgrLoginDelegate> xmppLogRegDelegate; //登录、注册代理
@property (nonatomic, weak) id <EWxChatMgrGroupDelegate> xmppGroupDelegate; //群组代理


@property (strong, nonatomic) NSString *apiEntranceType; //Api进入Case类型名称

@property (nonatomic,copy) completionBlock completion;
@property (nonatomic, copy) contactGroupsCompletionBlock contactGroupCb;

@property (strong, atomic) NSMutableArray *timerIdList; //reqTimer和reqId和reqRet数组


/************************连接和断开连接接口*************************/
- (BOOL)connect;
- (void)disconnect;

- (void)disconnectAfterSending;


+ (UcfgroupXMPPManger*)sharedInstance;

//判断当前登录用户是否登录成功
- (BOOL)isLogSuccess;




#pragma mark -------配置XML流-----------

- (void)setupStream;
- (void)teardownStream;


//上线
- (void)ucfgroupGoOnline;
//下线
- (void)goOffline;

#pragma mark ----------收发信息------------


#pragma mark - 发送文件之前的操作－－图片、语音、视频
- (void)sendFileForSize:(NSInteger)size
               fileName:(NSString *)imageName
               fileDate:(NSData *)imageData
            andDelegate:(id)delegate;

//- (void)addSomeBody:(NSString *)userId;

//将要发出消息CallBack
- (void)willSendMessageCallbackState:(ChatMsgState)state messageId:(NSString *)messageId error:(NSString *)error;

/***************************************独立使用接口---Begin**********************************/
//获取联系人好友列表
- (void)ucfgroup_queryRosterWithVer:(NSString *)verRoster;

//添加好友    name为用户JID账号
- (void)ucfgroup_AddFriendSubscribe:(NSString *)nameJid reqMsg:(NSString *)reqMsg;

//同意添加好友，name为好友账号
- (void)ucfgroup_AgreeAddBuddy:(NSString *)name;

//拒绝添加好友，name为好友账号
- (void)ucfgroup_rejectAgreeAddBuddy:(NSString *)name reason:(NSString *)reason;

//修改好友昵称，nameId为好友账号
- (void)ucfgroup_setNickname:(NSString *)nickName forUserId:(NSString *)nameId;

//删除好友，name为好友账号
- (void)ucfgroup_removeBuddy:(NSString *)name;




#pragma mark-----创建群相关Api-------
//创建群
/**
 *
 *  @param group_name 群组名称
 *  @param desc       群描述信息
 *  @param max
 *  @param yesorno    是否是公开群　０不公开，１公开
 *  @param isapproval 是否需要审批加入 此属性只针对公开群组有效
 */
- (void)ucfgroup_CreateGroupName:(NSString *)group_name
                            desc:(NSString *)desc
                       memberMax:(NSInteger)max
                        isPublic:(BOOL)yesorno
                      isApproval:(BOOL)isapproval;



#pragma mark-------处理查询是否返回超时------
//添加回应超时处理      reqTimer和reqId和paraMsg数组
- (void)addXmppRecordReqId:(NSString*)reqId type:(NSString*)type paraMsg:(id)paraMsg;

//分发转换成对应消息类型
- (id)distributeMsgType:(NSUInteger)msgType message:(MessageBase *)wxmsg;


//保存聊天文件
-(BOOL)saveChatFileName:(NSString *)fileName withData:(NSData *)data;
//检查文件绝对路径
- (NSString *)checkFileFullPathByFileName:(NSString *)filename;


//检查测试服务器Or正式服务器
- (NSString *)getFileServer;


#pragma mark -----------获取本地通讯录电话号码-----------
-(BOOL)getPhoneContacts:(NSMutableArray*)contactMutableArray;

- (NSString *)generateXMPPresource;

- (NSString *)convertToJid:(NSString *)jidName;


#pragma mark----上传设备Token----
- (BOOL)ucfgroup_uploadDeviceToken:(NSString *)deviceToken owner:(NSString *)owner;
#pragma mark----消息免打扰----
- (BOOL)ucfgroup_SetMessageTrouble:(BOOL)isTuouble connectid:(NSString *)connectid;

- (BOOL)ucfgroup_GetMessageTroubleConnectid:(NSString *)connectid;
#pragma mark----删除服务器聊天记录----
- (BOOL)ucfgroup_DeleteMessageWithConnectid:(NSString *)connectid;
@end
